package cn.chinaunicom.sdsi.gacx.workflow.elecmanage.service.impl;

import cn.chinaunicom.sdsi.gacx.workflow.elecmanage.entity.FlowCfgLink;
import cn.chinaunicom.sdsi.gacx.workflow.elecmanage.service.FlowCfgLinkService;
import cn.chinaunicom.sdsi.gacx.workflow.elecmanage.dao.mybatis.FlowCfgLinkMapper;
import cn.chinaunicom.sdsi.upfc_demp.jyxx.dao.mybatis.JyXxMapper;
import org.springframework.beans.factory.annotation.Autowired;
import cn.chinaunicom.sdsi.frm.sys.R;
import cn.chinaunicom.sdsi.frm.sys.entity.SysStaff;
import org.springframework.stereotype.Service;
import cn.chinaunicom.sdsi.frm.base.BaseService;
import com.github.pagehelper.PageInfo;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service
public class FlowCfgLinkServiceImpl extends BaseService implements FlowCfgLinkService{

	@Autowired
	private FlowCfgLinkMapper flowCfgLinkMapper;
	
	@Autowired
    private JyXxMapper jyXxMapper;
	/**
	 * 分页查询
	 */
	@Override
	public JSONObject search4PageList(FlowCfgLink flowCfgLink,Integer start, Integer length){
		setPageInfo(start,length);
		List<FlowCfgLink> beanList=flowCfgLinkMapper.search4PageList(flowCfgLink);
		PageInfo<FlowCfgLink> page = new PageInfo<FlowCfgLink>(beanList);
		JSONObject obj = null;
		JSONArray array = new JSONArray();
		
		for(FlowCfgLink bl :beanList){
			obj = new JSONObject();
					obj.put("flowLinkId",bl.getFLOW_LINK_ID());
			array.add(obj);
		}
		obj = new JSONObject();
		obj.element("data", array);
		obj.element("recordsTotal", page.getTotal());
		obj.element("recordsFiltered", page.getTotal());
		obj.element("draw", 0);
		return obj;
	}
	
	/**
	 * 查询单条数据
	 */
	@Override
	public FlowCfgLink selectByPrimaryKey(FlowCfgLink flowCfgLink){
		
		FlowCfgLink bean=flowCfgLinkMapper.selectByPrimaryKey(flowCfgLink);
		return bean;
	}
	
	/**
	 * 删除单条数据
	 */
	@Override
	public int deleteByPrimaryKey(FlowCfgLink flowCfgLink){
		int delnum = flowCfgLinkMapper.deleteByPrimaryKey(flowCfgLink);
		return delnum;
	}

	/**
	 * 保存数据
	 */
	@Override
	public int addObject(FlowCfgLink flowCfgLink){
		int insertnum = flowCfgLinkMapper.addObject(flowCfgLink);
		return insertnum;
	}

	/**
	 * 修改单条数据
	 */
	@Override
	public int updateByPrimaryKey(FlowCfgLink flowCfgLink){
		int updatetnum = flowCfgLinkMapper.updateByPrimaryKey(flowCfgLink);
		return updatetnum;
	}
	
    @Override
    public List<Map> selectStaffByELecApplyId(String elecApplyId) {
        return jyXxMapper.selectStaffByELecApplyId(elecApplyId);
    }

    @Override
    public List<Map> selectNextStaffBySessionStaffId() {
        SysStaff staff = (SysStaff)getSessionCache(R.UserSign.SIGNIN_USER_SESSION);
        int staffId =staff.getStaffId();
        return jyXxMapper.selectNextStaffBySessionStaffId(staffId);
    }
    @Override
    public List<Map> selectYwStaffBySessionStaffId() {
        SysStaff staff = (SysStaff)getSessionCache(R.UserSign.SIGNIN_USER_SESSION);
        int staffId =staff.getStaffId();
        return jyXxMapper.selectYwStaffBySessionStaffId(staffId);
    }
    @Override
    public List<Map> selectWgStaffBySessionStaffId() {
        SysStaff staff = (SysStaff)getSessionCache(R.UserSign.SIGNIN_USER_SESSION);
        int staffId =staff.getStaffId();
        return jyXxMapper.selectWgStaffBySessionStaffId(staffId);
    }
}